<?
$rtime 		= microtime();
$rtime 		= explode(" ",$rtime);
$rtime 		= $rtime[1] + $rtime[0];
$start_rb 	= $rtime;

require_once 'core/Debug.php'; //System Debug...
require_once 'core/config.php';//System Config...
require_once 'core/Init.php';  //System Init...

if(isset($_GET['mkseo']) && (int)$_GET['mkseo']==2010){
	$web_root = "http://enbac.com/";
	//header ("content-type: text/xml");
	$sitemap='<?xml version="1.0" encoding="UTF-8"?>
	<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url><loc>'.$web_root.'</loc></url>';
	
	$urllist = $web_root;
	
	foreach (array_keys(CGlobal::$subCategories) as $top_id){
		if(isset(CGlobal::$allCategories[$top_id]) && CGlobal::$allCategories[$top_id]){
			$ebname = CGlobal::$allCategories[$top_id]['ebname'];
			$sitemap.="\n".'<url><loc>'.$web_root.$ebname.'.rss</loc><changefreq>Daily</changefreq><priority>1.0</priority></url>';		
		}
	}
	
	foreach (CGlobal::$allZones as $zid=>$zone){
		$ebname = $zone['ebname'];	//cats	
		
		$sitemap.="\n".'<url><loc>'.$web_root.'z'.$zid.'/'.$ebname.'.html</loc><changefreq>Daily</changefreq><priority>1.0</priority></url>';
		$urllist.="\n".$web_root."z".$zid."/".$ebname.".html";
	}
	
	foreach (array_keys(CGlobal::$subCategories) as $top_id){
		if(isset(CGlobal::$allCategories[$top_id]) && CGlobal::$allCategories[$top_id]){
			$ebname = AZLib::safe_title(CGlobal::$allCategories[$top_id]['name']);
			
			$sitemap.="\n".'<url><loc>'.$web_root.'c'.$top_id.'/'.$ebname.'.html</loc><changefreq>Daily</changefreq><priority>1.0</priority></url>';		
			$sitemap.="\n".'<url><loc>'.$web_root.'c'.$top_id.'/'.$ebname.'/page-2.html</loc><changefreq>Daily</changefreq><priority>1.0</priority></url>';
			
			
			//UrlList:
			$urllist.="\n".$web_root."c".$top_id."/".$ebname.".html";
			$urllist.="\n".$web_root."c".$top_id."/".$ebname."/page-2.html";
			
			if(CGlobal::$subCategories[$top_id])
			foreach (CGlobal::$subCategories[$top_id] as $cat_levl_2){
				$ebname_sub ="-".AZLib::safe_title($cat_levl_2['name']);
				$ebname_all = $ebname.$ebname_sub;	
				
				$sitemap.="\n".'<url><loc>'.$web_root.'c'.$cat_levl_2['id'].'/'.$ebname_all.'.html</loc><changefreq>Daily</changefreq><priority>1.0</priority></url>';
				$sitemap.="\n".'<url><loc>'.$web_root.'c'.$cat_levl_2['id'].'/'.$ebname_all.'/page-2.html</loc><changefreq>Daily</changefreq><priority>1.0</priority></url>';
				
				//UrlList:
				$urllist.="\n".$web_root."c".$cat_levl_2['id']."/".$ebname_all.".html";
				$urllist.="\n".$web_root."c".$cat_levl_2['id']."/".$ebname_all."/page-2.html";
			}
		}
	}
	
	$sitemap.="\n".'</urlset>';
	file_put_contents("sitemap.xml",$sitemap);
	file_put_contents("urllist.txt",$urllist);
	
	echo $urllist,"<br /><br /><br /><br />";
	echo $sitemap,"<br /><br /><br /><br />";
	//redirect('sitemap.xml');
	exit;
}
elseif(CGlobal::$my_server){
	foreach (CGlobal::$my_server as $server){
		$link = "http://{$server}/seo.php?mkseo=2010";	
				
		if(@fopen($link,"r")){
			echo "run service in $link<br>";					
		}
		else{
			echo "error in $link<br>";
		}
	}
	
	$mtime = microtime();
	$mtime = explode(" ",$mtime);
	$mtime = $mtime[1] + $mtime[0];
	$end_rb = $mtime;			
	$page_load_time = round(($end_rb - $start_rb),5)."s";
	
	echo "Done in $page_load_time". "<br>";
}
?>
